<template>
	<view>
		<form style="background: white">
			<view class="cu-form-group margin-top">
				<view class="title">养殖仓库</view>
				<picker @change="PickerChange" :value="index" :range="breedingHousePicker">
					<view class="picker" style="text-align: right; color: #808080; font-size: 30rpx;">
						{{breedingHousePicker[index]}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">猪栏编号</view>
				<input maxlength="10" v-model="PigstyNo" placeholder="请输入猪栏编号" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
			<!-- <view class="cu-form-group">
				<view class="title">设备绑定</view>
				<picker @change="DevicePickerChange" :value="changeindex" :range="devicePicker">
					<view class="devicePicker" style="text-align: right; color: #808080; font-size: 30rpx;">
						{{devicePicker[changeindex]}}
					</view>
				</picker>
			</view> -->
		</form>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				index: 0,
				//changeindex: 0,
				PigstyNo: '',
				editorID: '',
				breedingHousePicker: [],
				warehouse_id_List: []
				
				//devicePicker: ['193.1.168.111', '193.1.168.112', '193.1.168.113']
			}
		},
		onNavigationBarButtonTap() {
			this.save()
		},
		methods: {
			PickerChange: function(e) {
				this.index = e.target.value
				//console.log(this.index)
			},
			// DevicePickerChange: function(e) {
			// 	this.changeindex = e.target.value
			// 	//console.log(this.changeindex)
			// },
			
			//保存
			save (index) {
				uni.request({
					url: this.confige.webUrl+'/livestock/updPigsty',
					data: {
						pigsty_id: this.editorID,
						pigsty_number: this.PigstyNo,
						farm_id: this.User.userInfo.farm_id,
						warehouse_id: this.warehouse_id_List[this.index],
						warehouse_name: this.breedingHousePicker[this.index]
					},
					method:"POST",
					header: {
						"X-Token":this.User.token
					},
					success: (res) => {
						console.log(res)
						if(res.data.code == 200){
							uni.showModal({
								title: "提示",
								showCancel: false,
								content: "修改成功",
								success: (res) => {
									if(res.confirm){
										uni.navigateBack({
											delta: 1
										})
									}
								}
							})	
						}
						else if(res.data.code == 400) {
							uni.showModal({
								title: "提示",
								showCancel: false,
								content: res.data.message
							})
							console.log("warehouse_id:" + this.warehouse_id_List[index]+"----warehouse_name:" 
							+ this.breedingHousePicker[index] + "---pigsty_id:" + this.editorID+
						"----pigsty_number:" + this.PigstyNo,)
						}
					}
					
				})
			},
			
			//初始化数据
			init () {
				uni.request({
					url:this.confige.webUrl+'/livestock/selWarehouse',
					data:{
						farm_id: this.User.userInfo.farm_id
					},
					header:{
						"X-Token":this.User.token
					},
					success: (res) => {
						console.log(res)
						//获取并设置养殖仓picker选择列表
						res.data.result.forEach((item,index) => {
							this.breedingHousePicker.push(item.warehouse_serial_number)
							this.warehouse_id_List.push(item.warehouse_id)
						})
						console.log(this.breedingHousePicker)
					}
				})
			}
		},
		onLoad(option) {
			this.init()
			setTimeout(() => {
				this.index = this.breedingHousePicker.indexOf(option.editorBreedingHouse)//设置picker养殖仓初始下标	
			},2000)
			//this.changeindex = this.devicePicker.indexOf(option.editorDevice)
			this.PigstyNo = option.editorPigstyNo//猪栏编号
			this.editorID = option.pystyID
		},
		onShow() {
			
		}
	}
</script>

<style lang="less">
	@import "../../../common/colorui/main.css";
	@import "../../../common/colorui/icon.css";
	
	page {
		background: #EEEEEE;
	}
	
	.save {
		width: 710rpx;
		height: 80rpx;
		position: fixed;
		bottom: 30rpx;
	}
	
	.save button {
		background-color: #4AC997;
		color: white;
		font-weight: bold;
		border-radius: 60rpx;
		margin-left: 40rpx;
		height: 80rpx;
	}
</style>
